//controlls
define(function (require, exports, module) {
    const Vue=require("vue");
    var template=require('text!./index.html');
    const api=require("api");
    const weui=require('weui');
    module.exports=Vue.extend({
        template:template,
        data:function () {
            return {
                user_credit_info:[]
            }
        },
        created:function () {

        },
        computed:{
            isBack:function () {
                return this.$store.getters.getIsBack;
            },
            user_info:function () {
                return this.$store.getters.getUserInfo;
            }
        },
        beforeRouteEnter:function (to,from,next) {
            next(function (vm) {
                if(!vm.isBack){
                    vm.getCreditInfo();
                }
            })
        },
        methods:{
            getCreditInfo:function () {
                var v=this;
                var loading = weui.loading('loading……');
                api.creditInfo(1,50,v.user_info).then(function (data) {
                    if(data.user_credit_info&&data.user_credit_info.return_code==="SUCCESS"){
                        v.user_credit_info=data.user_credit_info.credit_infos;
                    }else {
                        weui.topTips(data.user_credit_info.return_msg);
                    }
                }).catch(function (e) {
                    weui.topTips("网络异常，请刷新页面再试!");
                }).finally(function () {
                    loading.hide();
                });
            }
        },
        filters:{
            score:function (val) {
                val=parseInt(val);
                if(val>=0)
                    return "+"+val;
                return val;
            }
        }
    });
});